package com.rem.rabbitmq.ee.Brotation;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.rem.rabbitmq.ee.RabbitMqUtils;


/**
 * 消费者02
 *
 * @author Rem
 * @date 2021-12-23
 */

public class Consumer02 {

    public static void main(String[] args) throws Exception {

        Channel channel = RabbitMqUtils.getChannel();

        //消费回调
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("接收到的消息：" + new String(message.getBody()));
        };

        //取消消费回调 如果在消费的时候队列被删除了
        CancelCallback cancelCallback = consumerTag -> {
            System.out.println("消费消息被中断");
        };

        System.out.println("消费者02 等待消费");
        channel.basicConsume(RabbitMqUtils.QUEUE_ROTATION, true, deliverCallback, cancelCallback);
    }
}
